<template>
  <SettingDrawerWrapper>
    <a-drawer
      width="300"
      placement="right"
      @close="onClose"
      :closable="false"
      :getContainer="false"
      :visible="isSettingDrawerShow"
      :drawer-style="{ position: 'absolute' }"

    >
      <div class="setting-drawer-index-content">

        <div :style="{ marginBottom: '24px' }">
          <h3 class="setting-drawer-index-title">整体风格设置</h3>

          <div class="setting-drawer-index-blockChecbox">
            <a-tooltip>
              <template slot="title">
                暗色菜单风格
              </template>
              <div class="setting-drawer-index-item" @click="handleMenuTheme('dark')">
                <img src="https://gw.alipayobjects.com/zos/rmsportal/LCkqqYNmvBEbokSDscrm.svg" alt="dark">
                <div class="setting-drawer-index-selectIcon" v-if="config.theme === 'dark'">
                  <a-icon type="check"/>
                </div>
              </div>
            </a-tooltip>

            <a-tooltip>
              <template slot="title">
                亮色菜单风格
              </template>
              <div class="setting-drawer-index-item" @click="handleMenuTheme('light')">
                <img src="https://gw.alipayobjects.com/zos/rmsportal/jpRkZQMyYRryryPNtyIC.svg" alt="light">
                <div class="setting-drawer-index-selectIcon" v-if="config.theme !== 'dark'">
                  <a-icon type="check"/>
                </div>
              </div>
            </a-tooltip>
          </div>
        </div>

        <div :style="{ marginBottom: '24px' }">
          <h3 class="setting-drawer-index-title">主题色</h3>

          <div style="height: 20px">
            <a-tooltip class="setting-drawer-theme-color-colorBlock" v-for="(item, index) in primaryColorList" :key="index">
              <template slot="title">
                {{ item.name }}
              </template>
              <a-tag :color="item.value" @click="changeColor(item.value)">
                <a-icon type="check" v-if="item.value === config.primaryColor"></a-icon>
              </a-tag>
            </a-tooltip>
          </div>

          <a-list-item>
            <a-switch slot="actions" size="small" :defaultChecked="config.headerUsePrimary" @change="handleSwitchHeaderColor" />
            <a-list-item-meta>
              <div slot="title">顶部跟随主题色</div>
            </a-list-item-meta>
          </a-list-item>
        </div>
        <a-divider />

        <div :style="{ marginBottom: '24px' }">
          <h3 class="setting-drawer-index-title">导航模式</h3>

          <div class="setting-drawer-index-blockChecbox">
            <a-tooltip>
              <template slot="title">
                侧边栏导航
              </template>
              <div class="setting-drawer-index-item" @click="handleLayout('sidemenu')">
                <img src="https://gw.alipayobjects.com/zos/rmsportal/JopDzEhOqwOjeNTXkoje.svg" alt="sidemenu">
                <div class="setting-drawer-index-selectIcon" v-if="config.layout === 'sidemenu'">
                  <a-icon type="check"/>
                </div>
              </div>
            </a-tooltip>

            <a-tooltip>
              <template slot="title">
                顶部栏导航
              </template>
              <div class="setting-drawer-index-item" @click="handleLayout('topmenu')">
                <img src="https://gw.alipayobjects.com/zos/rmsportal/KDNDBbriJhLwuqMoxcAr.svg" alt="topmenu">
                <div class="setting-drawer-index-selectIcon" v-if="config.layout !== 'sidemenu'">
                  <a-icon type="check"/>
                </div>
              </div>
            </a-tooltip>
          </div>
          <div :style="{ marginTop: '24px' }">
            <a-list :split="false">
              <a-list-item>
                <a-tooltip slot="actions">
                  <template slot="title">
                    该设定仅 [顶部栏导航] 时有效
                  </template>
                  <a-select size="small" style="width: 80px;" :value="config.contentWidth" @change="handleContentWidthChange">
                    <a-select-option value="fixed" v-if="config.layout !== 'sidemenu'">固定</a-select-option>
                    <a-select-option value="fluid">流式</a-select-option>
                  </a-select>
                </a-tooltip>
                <a-list-item-meta>
                  <div slot="title">内容区域宽度</div>
                </a-list-item-meta>
              </a-list-item>
              <a-list-item>
                <a-switch slot="actions" size="small" :defaultChecked="config.fixedHeader" @change="handleFixedHeader" />
                <a-list-item-meta>
                  <div slot="title">固定 Header</div>
                </a-list-item-meta>
              </a-list-item>
              <a-list-item>
                <a-switch slot="actions" size="small" :disabled="!config.fixedHeader" :defaultChecked="config.autoHideHeader" @change="handleFixedHeaderHidden" />
                <a-list-item-meta>
                  <a-tooltip slot="title" placement="left">
                    <template slot="title">固定 Header 时可配置</template>
                    <div :style="{ opacity: !config.fixedHeader ? '0.5' : '1' }">下滑时隐藏 Header</div>
                  </a-tooltip>
                </a-list-item-meta>
              </a-list-item>
              <!-- <a-list-item >
                <a-switch slot="actions" size="small" :disabled="(config.layout === 'topmenu')" :defaultChecked="config.fixSiderbar" @change="handleFixSiderbar" />
                <a-list-item-meta>
                  <div slot="title" :style="{ textDecoration: config.layout === 'topmenu' ? 'line-through' : 'unset' }">固定侧边菜单</div>
                </a-list-item-meta>
              </a-list-item> -->
            </a-list>
          </div>
        </div>
        <a-divider />

        <div :style="{ marginBottom: '24px' }">
          <h3 class="setting-drawer-index-title">其他设置</h3>
          <div>
            <a-list :split="false">
              <a-list-item>
                <a-switch slot="actions" size="small" :defaultChecked="config.weakMode" @change="onColorWeak" />
                <a-list-item-meta>
                  <div slot="title">色弱模式</div>
                </a-list-item-meta>
              </a-list-item>
              <a-list-item>
                <a-switch slot="actions" size="small" :defaultChecked="config.multiTab" @change="onMultiTab" />
                <a-list-item-meta>
                  <div slot="title">多页签模式</div>
                </a-list-item-meta>
              </a-list-item>
            </a-list>
          </div>
        </div>
        <!-- <a-divider /> -->
      </div>
      <!-- <div class="setting-drawer-index-handle" @click="toggle" slot="handle">
        <a-icon type="setting" v-if="!isSettingDrawerShow"/>
        <a-icon type="close" v-else/>
      </div> -->
    </a-drawer>
  </SettingDrawerWrapper>
</template>

<script>
import { SettingDrawerWrapper } from './style'
import { mapGetters } from 'vuex'
import { updateTheme } from './settingConfig'

export default {
  components: {
    SettingDrawerWrapper,
  },
  computed: {
    ...mapGetters(['theme', 'config', 'primaryColorList', 'isSettingDrawerShow']),
  },
  data () {
    return {}
  },
  props: {
  },
  watch: {

  },
  mounted () {
    updateTheme(this.config.primaryColor, false)
  },
  methods: {
    onClose () {
      this.$store.commit('setSettingDrawerShow', false)
    },
    toggle () {
      this.$store.commit('setSettingDrawerShow', !this.isSettingDrawerShow)
    },
    onColorWeak (checked) {
      this.$store.commit('setConfig', { weakMode: checked })
    },
    onMultiTab (checked) {
      this.$store.commit('setConfig', { multiTab: checked })
    },
    handleMenuTheme (theme) {
      this.$store.commit('setConfig', { theme })
    },
    handleLayout (mode) {
      if (mode === 'sidemenu') {
        this.$store.commit('setConfig', { layout: mode, contentWidth: 'fluid' })
      } else {
        this.$store.commit('setConfig', { layout: mode })
      }
    },
    handleContentWidthChange (type) {
      this.$store.commit('setConfig', { contentWidth: type })
    },
    changeColor (color) {
      if (this.config.primaryColor !== color) {
        updateTheme(color)
        this.$store.commit('setConfig', { primaryColor: color })
      }
    },
    handleSwitchHeaderColor (checked) {
      this.$store.commit('setConfig', { headerUsePrimary: checked })
    },
    handleFixedHeader (fixed) {
      this.$store.commit('setConfig', { fixedHeader: fixed })
    },
    handleFixedHeaderHidden (autoHidden) {
      this.$store.commit('setConfig', { autoHideHeader: autoHidden })
    },
    handleFixSiderbar (fixed) {
      if (this.config.layout === 'topmenu') {
        this.$store.commit('setConfig', { fixSiderbar: false })
        return
      }
      this.$store.commit('setConfig', { fixSiderbar: fixed })
    },
  }
}
</script>
